/**
 * 将接口返回的参数转换成符合antd的一些组件的设置参数的结构类型
 *
 * @author 俞杰
 * @email 158392613@qq.com
 */

import { Pagination } from '#/antd'
import { PageRespData } from '@/api/types'

type FormatPaginationFun = (pageInfo: PageRespData) => Pagination
type FormatRequestPage = (pageInfo?: Pagination) => PageRespData
/**
 * 转换接口返回参数=>antd分页参数
 * @param pageInfo 接口分页参数
 * @returns
 */
export const formatPagination: FormatPaginationFun = (pageInfo) => {
  const { size } = pageInfo
  return {
    pageSize: size,
    current: pageInfo.current,
    total: pageInfo.total,
  }
}
export const formatRequestPage: FormatRequestPage = (pageInfo) => {
  if (pageInfo) {
    const { pageSize, ...restInfo } = pageInfo
    return {
      size: pageSize,
      ...restInfo,
    }
  }
  return {
    size: 20,
    current: 1,
    total: 0,
  }
}
